package com.wing.wcabinet.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.wcabinet.dao.WcabUseInventoryUserDao;
import com.wing.wcabinet.model.entity.WcabUseInventoryUser;
import com.wing.wcabinet.model.request.WcabUseInventoryUserForm;
import com.wing.wcabinet.model.response.WcabUseInventoryUserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 用户产品在用库存-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class WcabUseInventoryUserServiceImpl extends ServiceImpl<WcabUseInventoryUserDao, WcabUseInventoryUser> implements WcabUseInventoryUserService {

    @Override
    public int add(WcabUseInventoryUserForm wcabUseInventoryUserForm) {

        //校验

        WcabUseInventoryUser wcabUseInventoryUser =new WcabUseInventoryUser();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(WcabUseInventoryUser.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(wcabUseInventoryUserForm, wcabUseInventoryUser, copyOptions);

        return baseMapper.insert(wcabUseInventoryUser);
    }

    @Override
    public List<WcabUseInventoryUserVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<WcabUseInventoryUserVO> pageList4app(Page page, Map<String, Object> params) {
        List<WcabUseInventoryUserVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public WcabUseInventoryUserVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }
}
